#include <stdio.h>
#include <unistd.h>

#include "contr_suite.h"
#include "cam_suite.h"

int main(void) {
    int fd;

    fd = openFile();
    //setTio(fd);

    for (;;) {
        loadPictureBlocking();
        int width = camGetWidth(), height = camGetHeight();
        int row = height / 2, col = width / 2;
        analyzePicture(&row, &col);
//        savePicture();

        int steerValue = (width / 2 - col) * 50 * 2 / width;
        int speedValue = (row - height / 2) * 50 * 2 / height;

        char buf[100];
        buf[sprintf(buf, "steer %d\n\n", steerValue)] = 0;
        sendMessage(buf, fd);
        buf[sprintf(buf, "wheels %d\n\n", speedValue)] = 0;
        sendMessage(buf, fd);
    }
    close(fd);
    return 0;
}
